package com.example.administrator.uis.view.paintView

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import com.example.administrator.uis.R

/**
 * Created by Administrator on 2017/11/14 0014.
 */
class Practice05ComposeShaderView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
    var paint = Paint(Paint.ANTI_ALIAS_FLAG)
    var bitmap = BitmapFactory.decodeResource(resources, R.drawable.ydzx)
    var bitmapdown = BitmapFactory.decodeResource(resources, R.drawable.doge)
    var shaderUp = BitmapShader(bitmap, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR)
    var shaderdown = BitmapShader(bitmapdown, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
    //    var shaderHun=ComposeShader(shaderdown,shaderUp,PorterDuff.Mode.DST_OUT) //第二层相交空白
//    var shaderHun=ComposeShader(shaderdown,shaderUp,PorterDuff.Mode.DST_IN) //第一层相交显示不相交空白
//    var shaderHun=ComposeShader(shaderdown,shaderUp,PorterDuff.Mode.SRC_OVER)//共同存在
    var shaderHun = ComposeShader(shaderdown, shaderUp, PorterDuff.Mode.MULTIPLY) //混合

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setLayerType(LAYER_TYPE_SOFTWARE, null)//分层显示必须加入这个
        paint.shader = shaderHun
        canvas?.drawCircle(650f, 650f, 250f, paint)
    }
}